# -*- coding: utf-8 -*- 
# @project : 《剑指offer》
# @Author : created by bensonrachel on 2021/6/13
# @File : 删除链表的节点1.py

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None
class Solution:
    def deleteNode(self, head: ListNode, val: int) -> ListNode:
        x = head
        while(head.next):
            if(head.val==val):
                x=head.next
                break
            if(head.next.val==val):
                head.next = head.next.next
                break
            head = head.next
        return x